import request from '@/utils/request';

export interface LoginParams {
  username: string;
  password: string;
}

export interface UserInfo {
  id: string;
  username: string;
}

// 登录接口
export const login = (params: LoginParams) => {
  return request.post<{ token: string }>('/user/login', params);
};

// 获取用户信息
export const getUserInfo = () => {
  return request.get<UserInfo>('/user/info');
};

// 退出登录
export const logout = () => {
  return request.post('/user/logout');
};

/** 获取用户列表 */
export async function getUserList(params: {
  page?: number;
  pageSize?: number;
  username?: string;
  nickname?: string;
  role?: string;
  status?: boolean;
}) {
  return request.get('/users/list', { params });
}

/** 创建用户 */
export async function createUser(data: Record<string, any>) {
  return request.post('/users/create', data);
}

/** 更新用户 */
export async function updateUser(data: Record<string, any>) {
  return request.post('/users/update', data);
}

/** 删除用户 */
export async function deleteUser(data: { id: string }) {
  return request.post('/users/delete', data);
}
